import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:toatool/src/data/remote/dio_config.dart';
import 'package:toatool/src/data/remote/interceptor/header_interceptor.dart';
import 'package:toatool/src/data/remote/interceptor/response_interceptor.dart';

class DioConfigController extends GetxService {
  Future<DioConfig> init(String baseUrl) async {
    String? cookiesPath;
    if (!kIsWeb) {
      var appDocDir = await getApplicationDocumentsDirectory();
      cookiesPath = join(appDocDir.path, '.cookies/');
    }
    var dioConfig = DioConfig();
    dioConfig.init(
      baseUrl,
      interceptors: [
        HeaderInterceptors(),
        ResponseInterceptors(),
      ],
      cookiesPath: cookiesPath,
    );
    return dioConfig;
  }
}
